package com.service.core.exception;

import com.service.core.rest.response.OneResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

/**
 * Description: CommonExceptionHandler
 */
@Slf4j
@RestControllerAdvice
public class DBExceptionHandler {

    /**
     * 自定义异常
     */
    @ExceptionHandler(SQLException.class)
    public OneResponse handleDBException(SQLException e){
        log.error("SQLException:{}", e.getMessage());
        return new OneResponse<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "服务器异常,稍后再试",null);
    }
}
